package com.njwb.subject.mapper;

import com.njwb.subject.pojo.Subject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SubjectMapper {
    /**
     * 获取课题编号的最小值
     * @return
     */
    @Select("select min(no) from t_subject ")
    int getMinNo();

    /**
     * 获取课题编号的最大值
     * @return
     */
    @Select("select max(no) from t_subject ")
    int getMaxNo();

    /**
     * 获取未被选中的课题编号列表
     * @return
     */
    @Select("select no from t_subject where status = 0 ")
    List<Integer> getUnselectedNos();

    /**
     * 根据学号查询课题信息
     * @param sno
     * @return
     */
    @Select("select no,subject_name,teacher_name,teacher_contact,sno,sname,status from t_subject where sno = #{sno}")
    @ResultMap("SubjectMap")
    Subject getBySNo(String sno);


    /**
     * 根据课程编号查询课程信息
     * @param no
     * @return
     */
    @Select("select no,subject_name,teacher_name,teacher_contact,sno,sname,status from t_subject where no = #{no}")
    @ResultMap("SubjectMap")
    Subject getByNo(Integer no);
    /**
     * 更新课题
     * @param subject
     */
    @Update("update t_subject set sno = #{sno},sname = #{sname} ,status = 1 where no = #{no}")
    void update(Subject subject);



}
